package com.study.thread;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class SyncThisClass {

    Logger logger = LoggerFactory.getLogger(SyncThisClass.class);

    /**
     * @description 同步代码块传参this（锁住的是当前实例对象）
     * @author hw
     * @date 2022/1/1 22:48:10
     */
    public void test1(){
        synchronized (this){
            try {
                logger.info(Thread.currentThread().getName() + "test2 进入了同步块");
                Thread.sleep(5000);
                logger.info(Thread.currentThread().getName() + "test2 休眠结束");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
